$(myElementParams = function (elem) {
	var elem = ( typeof(elem) == "object" ) ? ( typeof(elem.jquery) == "undefined" ? elem : elem.get(0) ) : $(elem)[0];
	var left = 0;
	var top = 0;
	var width = elem.offsetWidth;
	var height = elem.offsetHeight;
	if (elem.offsetParent) {
		do {
				left += elem.offsetLeft;
				top += elem.offsetTop;
		} while (elem = elem.offsetParent);
	};
	if(self.innerWidth!=undefined) { A= [self.innerWidth,self.innerHeight];	}
	else {
		var D= document.documentElement;
		if(D) {A= [D.clientWidth,D.clientHeight];}
	}
	return {
		d: [width, height],
		p: [left, top]
	};
});






/* Присутствие
*********************************************************/
$(function() {
	var which = $(".mP a");
	yTest = false;
	which.hover(
		function () { $(this).css('cursor','pointer'); },
		function () {}
	);
	which.click(function(){
		yTest = true;
		var obj = $(this);
		var cid = obj.attr('id');
		var oldClass = obj.attr('class')
		var oldText = obj.text();
//		log.debug('oldClass = '+oldClass); log.debug('cid = '+cid);
		if(boxerInplace.inited == true) {
			boxerInplace.hide();
			obj.removeAttr('class').addClass(oldClass);
		}
		var text = '<div class="owBlock" style=""><ol style="list-style: none;">'
			+ '<li class="mpl1" title="mpOut"><a href=""  class="mpOut" title="неявка">неявка</a></li>'
			+ '<li class="mpl2" title="mpDelay"><a href="#" class="mpDelay" title="опоздание">опоздание</a></li>'
			+ '<li class="mpl3" title="mpIll"><a href="" class="mpIll" title="болезнь">болезнь</a></li>'
			+ '<li class="mpl4" title="mpPass"><a href="" class="mpPass" title="пропуск">пропуск</a></li>'
			+ '<li class="mpl5" title="mpNone"><a href="" class="mpNone" title="">отмена</a></li>'
			+ '</div>';
//		overlay = $('<div id="overlay"></div>').appendTo($("body")); // addon
		boxerInplace.show(obj , text , {delay : false ,className : "confirm2", xId:'boxerInplace2'});
		
		var linkObj = $('.owBlock li a');
		linkObj.hover(function(){
			if (yTest === true ) {
				var xClass = $(this).parent().attr('title');
				var xText = $(this).attr('title');
				obj.removeAttr('class').addClass(xClass);
				obj.empty().html(xText)
				$(this).click(function(){
					yTest = false;
					obj.removeAttr('class').addClass(xClass);
					boxerInplace.hide();
//					overlay.remove();
					return false;
				})
				/*overlay.click(function () {
					obj.removeAttr('class').addClass(oldClass);
					boxerInplace.hide();
					overlay.remove();
				});*/
			}
		},
		function(){
			if (yTest === true) {
				obj.removeAttr('class').addClass(oldClass);
//				obj.removeAttr('class').addAttr('class' , oldClass);
				obj.children().html(oldText);
			}
		});
			
//			linkObj.click(function(){return false;});
		
	});
});






/* Коментарии
 ******************************************************/
$(function() {
	var which = $(".mC div span");

	which.click(function(){
		if(boxerInplace.inited == true) {
				boxerInplace.hide();
			}
		if (myComment.active != true) {
			var zArea = myComment.show($(this));
			boxerHelper.show($(this), 'для сохранения нажмите "Enter", или просто кликните за пределами формы, нажатие "Esc" отменит изменения',
				{delay: false ,className : "helper", xId:'helper', xTop : 95});
		}
		zArea.blur(function(){
//			$('.owButSubmit').click(function(){myComment.hideOk();});
			boxerHelper.hide();
			myComment.hide();
		});
		zArea.keypress(function (e) {
			if (e.keyCode == 13){ myComment.hide(); boxerHelper.hide(); }
			else if (e.keyCode == 27) {
				myComment.zEscFlag = true;
				myComment.hide();
				boxerHelper.hide();
			}
		});

	});
	var destr = $(".mC div a");
	destr.click(function(){
		/*boxerInplaceConfirm(
				this, 
				"Подтверждаете удаление?", 
				function () {
					myComment.destroy($(this));
				});*/
			myComment.destroy($(this));
			return false;
	});
});


/*
 * все функции стартуют от контролов событий прописанных отдельно (выше)
 */
(function($){
myComment = {
	options : {
		buttons : []
		,zActive : false
		,zTextDefault : 'нажмите что бы добавить коментарий'
	},
	
	show: function (element) {
		var zThis = element;
		this.zElement = element;
		this.zTextOld = zThis.html();
		this.zOldType = zThis.parent().attr('class');
		this.zElement.parent().removeClass(this.zOldType);

		var zAreaText = '';
		if (this.zOldType == 'mcText') {zAreaText = this.zTextOld;}
		var zHtml = '<div class="zDiv" style="z-index:1000;"><textarea style="font-size:12px; width:210px; height:65px;" class="zText">'
				+ zAreaText + '</textarea>'
				+'</div>';
		
		if (this.active != true) {
//		$('<div style="position:absolute; top:0; left:0; width:100%; height:100%; z-index:100;" id="overlay"></div>').appendTo($("body"));
			zThis.empty().html(zHtml);
			this.zElement.parent().find('a').hide();
			var zArea = zThis.find('textarea');
			zArea.focus();
		
			this.active = true;
			return zArea;
		}
	},
	/*
	 * "прячет" textarea сохраняя результат
	 */
	hide: function() {
		this.zNewText = $('.zDiv textarea').val();
		if(this.zNewText == '') {
			//myAjax.response();
			this.zElement.parent().addClass('mcNone');
			zHtmlOut = this.options.zTextDefault;
			this.zElement.parent().find('a').hide();
		}
		else if(this.zNewText != '' && this.zEscFlag == true && this.zOldType == 'mcText') {
//			if (this.zOldType != 'mcNone') {this.zElement.parent().addClass('mcText');}
			this.zElement.parent().addClass('mcText');
			zHtmlOut = this.zTextOld;
		}
		else {
			zHtmlOut = ''+ this.zNewText +'';
			this.zElement.parent().addClass('mcText');
			this.zElement.parent().find('a').show();
		}
//		if (this.zzHtml != '') {zHtmlOut = this.zzHtml; }
//		alert(this.zzHtml);
		this.zElement.empty().html(zHtmlOut);
		
		this.zEscFlag = false;
		this.active = false;
	},
	/*
	 * удаляет текст комментария и сбрасывает на дефолты
	 */
	destroy : function(element) {
		element.parent().removeClass().addClass('mcNone');
		zHtmlOut = this.options.zTextDefault;
		element.parent().find('span').empty().html(zHtmlOut);
		element.hide();
	}
};
})(jQuery);







/* Marks
*****************************************************************/
$(function() {
	var arrMarks = ['1-', '1', '1+', '2-', '2', '2+', '3-', '3', '3+', '4-', '4', '4+', '5-', '5', '5+'];
//	$('.test1').html(arrMarks[8]);
	
	var which = $('li.mmPlace');
	var xTest = false;
	
	which.hover(
		function () { $(this).addClass('mmHover');},
		function () { $(this).removeClass('mmHover'); }
	);
	
	which.click(function() {
		var obj = $(this);
		var cid = obj.attr('id');
		var oldClass = obj.attr('class')
		var oldMark = obj.html();
		xTest = true;

		if(boxerInplace.inited == true) {
			boxerInplace.hide();
			obj.removeAttr('class').addClass(oldClass);
		} else {
			var text = '<div class="owBlock" style=""><ol style="list-style: none;">'
				+ '<li class="mml1" title="mmOne"><a href="" class="mmHide" title="1-">1-</a><a href="" class="mm1" title="1">1</a><a href="" class="mmHide" title="1+">1+</a></li>'
				+ '<li class="mml2" title="mmTwo"><a href="" class="mmHide" title="2-">2-</a><a href="#" class="mm2" title="2">2</a><a href="" class="mmHide" title="2+">2+</a></li>'
				+ '<li class="mml3" title="mmThree"><a href="" class="mmHide" title="3-">3-</a><a href="" class="mpIll" title="3">3</a><a href="" class="mmHide" title="3+">3+</a></li>'
				+ '<li class="mml4" title="mmFor"><a href="" class="mmHide" title="4-">4-</a><a href="" class="mpPass" title="4">4</a><a href="" class="mmHide" title="4+">4+</a></li>'
				+ '<li class="mml5" title="mmFive"><a href="" class="mmHide" title="5-">5-</a><a href="" class="mpNone" title="5">5</a><a href="" class="mmHide" title="5+">5+</a></li>'
				+ '</ol><div class="mmDelet"><a href="">удалить</a></div>'
				+ '</div>';
//			overlay = $('<div id="overlay"></div>').appendTo($("body")); // addon
			boxerInplace.show(obj , text , {delay : false ,className : "confirm2", xId:'boxerInplace3'});
			
			var linkObj2 = $('.owBlock li');
			linkObj2.hover(
			function(){
				if( xTest === true) {
					var xMarkObj = $(this).find('a'); 
					xMarkObj.css('width','27px');
					var xHidden = $(this).find('a.mmHide');
					xHidden.css('display' , 'block');
				}
			},
			function () {
				if( xTest === true) {
					$(this).find('a').css('width','90px');
					xHidden = $(this).find('a.mmHide');
					xHidden.css('display' , 'none');
				}
			}
			);
			
			var linkObj = $('.owBlock li a');
			linkObj.hover(function() {
				if( xTest === true) {
					var xClass = $(this).parent().attr('title');
					var xText = $(this).attr('title');
					var xWindMarkVal = $(this).text();
				
					//obj.removeAttr('class').addClass(xClass);
					//obj.children().empty().html(xText)
					
					obj.text(xWindMarkVal);
					$(this).click(function(){
						//obj.removeAttr('class').addClass(xClass);
						xTest = false;
						obj.text(xWindMarkVal);
						boxerInplace.hide();
//						overlay.remove();
						return false;
					})
					/*overlay.click(function () {
						obj.removeAttr('class').addClass(oldClass);
						boxerInplace.hide();
						overlay.remove();
					});*/
				}
			},
			function(){
				if( xTest === true) {
//					obj.removeAttr('class').addClass(oldClass);
//					obj.children().html(oldMark);
					obj.html(oldMark);
			}});
			$('div .mmDelet').click(function() {
				obj.html('<span>x</span>');
				boxerInplace.hide();
				return false;
			});
		}
	});
});
	






(function($){ myAjax = {
	option : {
		simpleAjax : false
	},
	response : function() {
		$('.test1').fadeOut(1000, function(){alert('OK');});
	}
};
})(jQuery);



/*
*************************************************************************/
(function($) {
boxerHelper = {
	nativeOptions : {
		buttons : [],
		delay : 2000
	},
	show: function (element, text,  options ) {
		var element = ( typeof(element) == "object" ) ? ( typeof(element.jquery) == "undefined" ? element : element.get(0) ) : $(element)[0];
		this.element = element;
		this.options = {};
		$.extend( this.options, this.nativeOptions, options );
		var params = this.elementParams( element );
		
		this.zId = (this.options.xId != '') ? this.options.xId : 'helper';
		this.zTop = (this.options.xTop != '') ? this.options.xTop : '0';
		
		this.init(); /* INIT */
		this.html.text.html( text );
		this.html.css( {
			left: params.p[0] + params.d[1] + 20, /* gorysont */
			top: params.p[1] - this.zTop /* vertical*/
		});
		this.html[0].className = this.options.className || "";
		if (this.timeToClose) { clearTimeout(this.timeToClose); };
//		this.overlay.hide().fadeIn(200); // addon
		this.html.hide().fadeIn(200);
		if (this.options.delay) { this.timeToClose = setTimeout( function () { boxerInplace.hide(); }, this.options.delay ); };
		
	},
	hide: function () {
		this.html.fadeOut(1 , function(){ $(this).remove(); });
		this.inited = false;
	},
	init: function () {
		if (this.inited) { return false; };
		
		this.html = $('<div id="'+ this.zId +'"><p class="text"></p><div><hr/></div></div>')
			.appendTo($("body")).hide();
		this.html.text = this.html.find(".text");
		
		this.inited = true;
	},
	elementParams: function ( element ) {
		var left = 0;
		var top = 0;
		var width = element.offsetWidth;
		var height = element.offsetHeight;
		if (element.offsetParent) {
			do {
					left += element.offsetLeft;
					top += element.offsetTop;
			} while (element = element.offsetParent);
		};
		
		/* -redacted- */
		var A;
		if(self.innerWidth!=undefined) { A= [self.innerWidth,self.innerHeight];	} else {
			var D= document.documentElement;
			if(D) {A= [D.clientWidth,D.clientHeight];}
		}
		if (Math.round(A[0]) < 1190) { left = left-(left-Math.round(A[0])+200);}
		return {
			d: [width, height],
			p: [left, top]
		};
	}
};
})(jQuery);


/*$(function(){
	$('tbody tr').hover(
		function () {
			this.xzx = $(this).css('background');
			$(this).css('background' , '#f2f2f2');
		},
		function () {
			$(this).css('background' , this.xzx);
		}
	);
//	$('td').mouseover(function() { alert('dsdsd'); });
});*/

$(function(){
	$('tbody tr').mouseover(function () {
		$(this).addClass('toggle');
	});
	$('tbody tr').mouseout(function () {
		$(this).removeClass('toggle');
	});
//	$('td').mouseover(function() { alert('dsdsd'); });
});








/* переход по Key
******************************/
$(function() {
//	$('td input').focus(function() {
		
		$('td input').keypress(function(e){
			xThis = $(this);
			xFocus = null;
			var len = $('tbody tr').length; // удалить
			var xInpId = xThis.attr('id');
			log.debug('xInpId- '+xInpId);
			var xInputStringId = xInpId.split('-');
			a = parseInt(xInputStringId[0]);
			b = parseInt(xInputStringId[1]);
			log.info('a= '+ a+ ' b= '+ b);
			
			// ENTER
			if (e.keyCode == 13){
				if (a <= len) {
					a = a+1;
					xFocus = document.getElementById(a + '-' + b);
				} else {
					b = b + 1;
					xFocus = document.getElementById(0 + '-' + b);
				}
			}
			/*else if (e.keyCode == 37){
				var xInpId = xThis.attr('id');
				var xInputStringId = xInpId.split('-');
				xInputStringId[1] = parseInt(xInputStringId[1])-1
				var xFocus = document.getElementById(xInputStringId[0] + '-' + xInputStringId[1]);
				//log.info(xInputStringId[1]);
				if (xFocus == null) {
					xInputStringId[0] = parseInt(xInputStringId[0])-1;
					xFocus = document.getElementById(xInputStringId[0] + '-' + '5');
				}
//				xFocus.focus();
			}
			else if (e.keyCode == 39){
				var xInpId = xThis.attr('id');
				var xInputStringId = xInpId.split('-');
				xInputStringId[1] = parseInt(xInputStringId[1])+1
				var xFocus = document.getElementById(xInputStringId[0] + '-' + xInputStringId[1]);
				if (xFocus == null) {
					aaa = parseInt(xInputStringId[0]);
					ddd = aaa + 1;
//					alert(ddd);
					xFocus = document.getElementById(ddd + '-' + '1');
//					log.info(xInputStringId[0]);
				}
//				xFocus.focus();
			}*/
			e = null;
			xInputStringId = null;
			xThis = 'fdsf';
			a = null;
			b = null;
			xFocus.focus();
			log.debug('a= '+ a+ ' b= '+ b);
		});
//	});
});






/* темпы
**************************************************************/
/*$(function() {
$('.mL').click(function() {
	alert($(this)[0].tagName);
});
});*/


/**
 * дампер свойств обьекта
 * 
 * @param {} obj
 * @param {} obj_name
 * @return {}
 */
function dump(obj, obj_name) {
  var result = '';
  for (var i in obj)
    result += obj_name + '.' + i + ' = ' + obj[i] + '\n';
  return result
}
